﻿//Onload method
function onLoadChecks() {
    var divId = returnHiddenDivID();
    var divToShow = document.getElementById(divId);
    divToShow.style.display = 'block';
    removeButtonContainerStyling();
    setButtonContainerStyling(divId);
    showHideButtons(divId);
}
//find the visible div ID from the hidden control on the page
function returnHiddenDivID() {
    var divId = document.getElementById('<%=hiddenDivId.ClientID%>').value.toString();
    return divId;
}
//set the hidden visible div ID value using Javascript
function setHiddenDivID(sender) {
    var divId = document.getElementById('<%=hiddenDivId.ClientID%>');
    divId.value = sender.id.toString();
}
//hide all of the other divs on the page
//Sender:   Send the div you want to show 
function hideOtherDivs(DivToShow) {
    for (i = 1; i <= 6; i++) {
        var Div = document.getElementById('Tab' + i);
        Div.style.display = 'none';
    }
    DivToShow.style.display = 'block';
}

/*---------- Show / Hide Buttons ----------*/
//if the tab is the first or last then hide the button as necessary
//Sender:   Send the tab ID 
function showHideButtons(sender) {
    if (sender == 'Tab1') {
        hideBackButton();
        showNextButton();
    }
    else if (sender == 'Tab6') {
        showBackButton();
        hideNextButton();
    }
    else {
        showBackButton();
        showNextButton();
    }
}
function hideBackButton() {
    var BackButton = document.getElementById('Navigation_Button_Back');
    BackButton.style.display = 'none';
}

function hideNextButton() {
    var NextButton = document.getElementById('Navigation_Button_Next');
    NextButton.style.display = 'none';
}
function showNextButton() {
    var NextButton = document.getElementById('Navigation_Button_Next');
    NextButton.style.display = 'inline';
}
function showBackButton() {
    var BackButton = document.getElementById('Navigation_Button_Back');
    BackButton.style.display = 'inline';
}

/*---------- Styling  ----------*/

//Sender: tab ID for styling to be set for
function setButtonContainerStyling(sender) {
    var BreadCrumbContainerName = 'BreadCrumbContainer_Button_' + sender;
    var BreadCrumbContainer = document.getElementById(BreadCrumbContainerName);
    BreadCrumbContainer.className = BreadCrumbContainerName;
}

function removeButtonContainerStyling() {
    for (i = 1; i <= 6; i++) {
        var ButtonContainer = document.getElementById('BreadCrumbContainer_Button_Tab' + i);
        ButtonContainer.className = 'Breadcrumb_Button_Container';
    }
}

/*---------- Button Events ----------*/
function backButtonClick() {
    //if you have clicked the back button then the next button should be visible if it's not already
    showNextButton();
    var currentVisibleDivId = returnHiddenDivID();
    //just in case there is an error with the back button, check to see if it is the first div
    if (currentVisibleDivId != 'Tab1') {
        var currentVisibleDivNumber = currentVisibleDivId.match(/\d+$/)[0];
        var previousDivNumber = parseInt(currentVisibleDivNumber) - 1;
        var previousDivToShow = document.getElementById('Tab' + previousDivNumber);
        hideOtherDivs(previousDivToShow);
        setHiddenDivID(previousDivToShow);
        removeButtonContainerStyling();
        setButtonContainerStyling(previousDivToShow.id.toString());
        showHideButtons(previousDivToShow.id.toString());
    }
}
function nextButtonClick() {
    //if you have clicked the next button then the back button should be visible if it's not already
    showBackButton();
    var currentVisibleDivId = returnHiddenDivID();
    //just in case there is an error with the next button, check to see if it is the final div
    if (currentVisibleDivId != 'Tab6') {
        var currentVisibleDivNumber = currentVisibleDivId.match(/\d+$/)[0];
        var nextDivNumber = parseInt(currentVisibleDivNumber) + 1;
        var nextDivToShow = document.getElementById('Tab' + nextDivNumber);
        hideOtherDivs(nextDivToShow);
        setHiddenDivID(nextDivToShow);
        removeButtonContainerStyling();
        setButtonContainerStyling(nextDivToShow.id.toString());
        showHideButtons(nextDivToShow.id.toString());
    }
}
function tabButtonShowDiv(sender) {
    //find the div name of the button that has been clicked
    var DivToShowName = sender.name.split("_")[1];
    showHideButtons(DivToShowName);
    var DivToShow = document.getElementById(DivToShowName);
    hideOtherDivs(DivToShow);
    removeButtonContainerStyling();
    setButtonContainerStyling(DivToShowName);
    setHiddenDivID(DivToShow);
}